#include "MainFrame.h"

#include "XMain.h"
#include "wx/wxprec.h"
#include <wx/wx.h>
#include "xEngineEdit.h"
#include "RenderWin.h"



BEGIN_EVENT_TABLE(MainFrame, BaseFrame)

EVT_CLOSE(MainFrame::OnClose) 

END_EVENT_TABLE()


MainFrame::MainFrame( wxWindow* parent )
:
BaseFrame( parent ),m_LeftWinPercent(0.8f)
{


	m_Mainsplitter->SetSashPosition(m_LeftWinPercent*this->GetClientSize().GetWidth());
}
 

void MainFrame::OnSize( wxSizeEvent& event )
{


	wxSize size =m_View->GetSize();
	m_Mainsplitter->SetSashPosition(size.GetWidth()*m_LeftWinPercent);
	wxFrame::OnSize(event);
	// TODO: Implement OnSize
}

void MainFrame::OnSplitterSashChanged( wxSplitterEvent& event )
{
	float position = event.GetSashPosition();
	int width    = m_View->GetSize().GetWidth();
	m_LeftWinPercent = position/width;
}



void MainFrame::OnClickMenuItemExit( wxCommandEvent& event )
{



	//this->Destroy();
	//
	//this->DestroyChildren();
	this->Close(true);

	//extern MyApp& wxGetApp();
	// wxGetApp().CleanUp();

	return;
}


void MainFrame::OnClose(wxCloseEvent& event)
{
	BaseFrame::OnCloseWindow(event);

}

void MainFrame::OnSplitterChanged( wxSplitterEvent& event )
{

	//*
	XE::XEngine* pEngine = XE::XEngine::getSingletonPtr();
	if(pEngine!=NULL)
	{

       wxSize size ;
		size = m_RightPanel->GetClientSize();
		XE::xRenderTarget* pAttachTarget =  pEngine->GetRenderSystem()->GetAttachRenderTarget("attachTarget");
		if(pAttachTarget!=NULL)
		{
          	pAttachTarget->Resize(size.GetWidth(),size.GetHeight());
		}
	


		size =  m_RenderWin->GetClientSize();
		UINT w  =size.GetWidth();
		UINT h = size.GetHeight();
		pEngine->GetRenderSystem()->GetPrimaryRenderTarget()->Resize(w,h);






	}//*/
	return ;
}

//void   MainFrame::KeyDown (wxKeyEvent& event)
//{
//   event.Skip();
//   return ;
//
//}